package edu.msg.hrappy.backend.model;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;

@Entity
@Table(name = "Candidate")
public class Candidate extends BaseEntity {

    /**
     *
     */
    private static final long serialVersionUID = 1L;
    private String firstName;
    private String lastName;
    private byte[] cv;
    private String fileName;
    private Date date;
    private List<User> interviewers;
    private List<Comment> comments;
    private String phoneNumber;
    private String mobilePhoneNumber;
    private String email;
    private String address;
    private Boolean relocate;
    private Job job;
    private int accept;

    public Candidate() {
    }

    public Candidate(String firstName, String lastName, byte[] cv, Date date,
            List<User> interviewers, List<Comment> comments,
            String phoneNumber, String mobilePhoneNumber, String email, String address,
            Boolean relocate, Job job, String fileName) {
        this.lastName = lastName;
        this.firstName = firstName;
        this.cv = cv;
        this.date = date;
        this.interviewers = interviewers;
        this.comments = comments;
        this.phoneNumber = phoneNumber;
        this.mobilePhoneNumber = mobilePhoneNumber;
        this.email = email;
        this.address = address;
        this.relocate = relocate;
        this.job = job;
        this.fileName = fileName;
        this.accept = 0;
    }

    public Candidate(Long id, String firstName, String lastName, byte[] cv, Date date,
            List<User> interviewers, List<Comment> comments,
            String phoneNumber, String mobilePhoneNumber, String email,
            String address, Boolean relocate, Job job, String fileName) {
        super(id);
        this.lastName = lastName;
        this.firstName = firstName;
        this.cv = cv;
        this.date = date;
        this.interviewers = interviewers;
        this.comments = comments;
        this.phoneNumber = phoneNumber;
        this.mobilePhoneNumber = mobilePhoneNumber;
        this.email = email;
        this.address = address;
        this.relocate = relocate;
        this.job = job;
        this.fileName = fileName;
        this.accept = 0;
    }

    @Column(name = "firstName")
    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    @Column(name = "lastName")
    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @Column(name = "cv")
    public byte[] getCv() {
        return cv;
    }

    public void setCv(byte[] cv) {
        this.cv = cv;
    }

    @Temporal(javax.persistence.TemporalType.DATE)
    @Column(name = "date")
    public Date getDate() {
        return (date == null) ? null : (Date) date.clone();
    }

    public void setDate(Date date) {
        this.date = date;
    }

    @ManyToMany
    @JoinTable(name = "CANDIDATE_USER",
            joinColumns = {
                @JoinColumn(name = "CANDIDATE_ID")},
            inverseJoinColumns = {
                @JoinColumn(name = "USER_ID")})
    public List<User> getInterviewers() {
        return interviewers;
    }

    public void setInterviewers(List<User> interviewers) {
        this.interviewers = interviewers;
    }

    @OneToMany(cascade = {CascadeType.ALL})
    @JoinColumn(name = "CANDIDATE_ID")
    public List<Comment> getComments() {
        return comments;
    }

    public void setComments(List<Comment> comments) {
        this.comments = comments;
    }

    @Column(name = "phoneNumber")
    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    @Column(name = "mobilePhoneNumber")
    public String getMobilePhoneNumber() {
        return mobilePhoneNumber;
    }

    public void setMobilePhoneNumber(String mobilePhoneNumber) {
        this.mobilePhoneNumber = mobilePhoneNumber;
    }

    @Column(name = "email")
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Column(name = "address")
    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Column(name = "relocate")
    public Boolean getRelocate() {
        return relocate;
    }

    public void setRelocate(Boolean relocate) {
        this.relocate = relocate;
    }

    @ManyToOne
    @JoinColumn(name = "JOB_ID")
    public Job getJob() {
        return job;
    }

    public void setJob(Job job) {
        this.job = job;
    }

    @Column(name = "fileName")
    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public void setComment(Comment comment) {
        this.comments.add(comment);
    }

    public void addInterviewer(User user) {
        this.interviewers.add(user);
    }

    public void removeInterviewer(User user) {
        this.interviewers.remove(user);
    }

    @Column(name = "accept")
    public int getAccept() {
        return accept;
    }

    public void setAccept(int accept) {
        this.accept = accept;
    }

	public void removeComment(Comment comment) {
		this.comments.remove(comment);
		
	}

}
